package com.frog.common.util;

import com.alibaba.fastjson.JSON;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

/**
 * @author wuqiong 2022/3/22
 * @description
 */
public class SetBuilderUtil {


    public static <V> SetBuilderUtil.SetBuilder<V> add(V v) {
        return new SetBuilderUtil.SetBuilder<V>(v);
    }

    public static class SetBuilder<V> {

        private Set<V> set = new HashSet<>();

        SetBuilder(V v) {
            set.add(v);
        }

        public SetBuilderUtil.SetBuilder<V> add(V v) {
            set.add(v);
            return this;
        }
        public SetBuilderUtil.SetBuilder<V> addAll(Set<? extends V> s) {
            set.addAll(s);
            return this;
        }

        public Set<V> build() {
            return set;
        }

        public String toJsonString() {
            return JSON.toJSONString(set);
        }
    }
}
